<?php

/**
 * @author Samrat Khan
 * @author Zorj
 * Sep 26, 2013 - 10:24:23 AM
 */
ob_start();
$host = 'localhost';
$user = 'root';
$pass = 'samraj77';
$db = 'final_warehouse';
//$table = 'stockin';
$file = 'ReturnNote';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$values = mysql_query(
       "SELECT so.response_type_id, so.stockout_id, so.requestnumber, so.serialno, so.productid, so.siteid, so.receivedtime, so.out_quantity, so.uom, rn.note_id, rn.stockout_id, rn.backstatus, rn.inserteddate 
        FROM stockout so, returnnote rn 
        WHERE so.stockout_id = rn.stockout_id AND rn.backstatus = '0' AND rn.cus_id = '$cus_id' AND so.response_type_id !=11");
						
$headings = array( 'Request Number', 'Serial Number','Product Id','Site Name','Received Time','Stock Out Quantity','UOM','Inserted Date');
$i = 0;
foreach ($headings as $heading) {
    $csv_output .= $heading . ", ";
    $i++;
}
$csv_output .= "\n";
while ($rowr = mysql_fetch_row($values)) {
for ($j = 0; $j < $i; $j++) {
        $csv_output .= '"'.$rowr[$j] . '",';
    }
$csv_output .= "\n";
}
ob_end_clean();



$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
//header("Content-type: text/csv");
header('Content-Length: ' . strlen($csv_output) );
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
